﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.UserManagement;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DataAccess.Administration.UserManagement;
using System.Configuration;
using SIPO.Web.Support;
using System.Globalization;

namespace SIPO.Web.Forms.Transaction
{
    public partial class ObjectionDecisionsform : BasePage
    {
        private int id = -1;
        private int add = 0;
        private decimal isvalue = 0;
        private decimal isdecision = 0;
       // private string isinvoice = "";
        protected override void OnLoad(EventArgs e)
        {
            if (Request.Params["id"] != null)
            {
                id = Convert.ToInt32(Request.Params["id"]);
            }
            if (Request.Params["isedit"] != null)
            {
                add = Convert.ToInt32(Request.Params["isedit"]);
            }
            if (Request.Params["isvalue"] != null)
            {
                isvalue = Convert.ToDecimal(Request.Params["isvalue"].ToString());
            }
            if (Request.Params["isdecision"] != null)
            {
                isdecision = Convert.ToDecimal(Request.Params["isdecision"].ToString());
            }
            //if (Request.Params["isinvoice"] != null)
            //{
            //    isinvoice = Request.Params["isdecision"];
            //}

            if (add == 0)
            {
                recObjectionRepo objectionDal = new recObjectionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                recObjection objection = objectionDal.GetById(id);
                recBilling billing = new recBilling();

                hfTambah.Value = "1";
                hfID.Value = id.ToString();
                hfDebtorSectorId.Value = objection.DebtorSectorID.ToString();
                hfSanctionNo.Value = objection.SanctionNo;
                hfTransTypeId.Value = billing.TransTypeID.ToString();
                hfObjectionNo.Value = objection.ObjectionNo;
                hfSanctionValue.Value = isvalue.ToString();
                GetPrivilege();
                hfBillingNo.Value = objection.BillingNo;
            }
            else
            {
                recObjectionRepo objectionDal = new recObjectionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
                recObjection objection = objectionDal.GetById(id);

                hfID.Value = id.ToString();
                txtNoSuratKeputusan.Text = objection.DecisionNo;
                txtNoSuratTanggapan.Text = objection.ResponNo;
                txtTglTanggapan.Text = objection.ResponDate.HasValue ? objection.ResponDate.ToString() : "";
                decimal value = Convert.ToDecimal(objection.ObjectionValue);
                txtNoSuratKeputusan.Text = objection.DecisionNo;
                decimal value1 = Convert.ToDecimal(objection.DecisionValue);
                txtNilai.Text = value1.ToString();
                txtTglSurat.Text = objection.DecisionDate.HasValue ? objection.DecisionDate.ToString() : "";
                txtcatatan.Text = objection.DecisionNote;
                hfDebtorSectorId.Value = objection.DebtorSectorID.ToString();
                decimal valuedecision = Convert.ToDecimal(objection.DecisionValue);
                decimal valuesanksi = Convert.ToDecimal(objection.SanctionValue);
                if (objection.Decision == "Diterima")
                {
                    rbDiterima.Checked = true;
                    hfRadio.Value = objection.Decision;
                    txtNilai.Enabled = true;
                    hfDiterima.Value = valuedecision.ToString();
                    hfSanctionValue.Value = valuesanksi.ToString();
                }
                else if (objection.Decision == "Ditolak")
                {
                    rbDitolak.Checked = true;
                    hfRadio.Value = objection.Decision;
                    txtNilai.Enabled = false;
                    hfSanctionValue.Value = valuesanksi.ToString();
                }
                else if (objection.Decision == "Diterima Sebagian")
                {
                    rbDiterimaSebagian.Checked = true;
                    hfRadio.Value = objection.Decision;
                    txtNilai.Enabled = true;
                    hfDecisionValue.Value = valuedecision.ToString();
                    hfSanctionValue.Value = valuesanksi.ToString();
                }
                    
                    
                hfObjectionNo.Value = objection.ObjectionNo;

                GetPrivilege();
            }


        }
        private void GetPrivilege()
        {
            Membership membership = new Membership(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

            List<recAccessRights.AccessRights> accessRights = membership.GetAccessRights(base.UserID, base.MenuID);

            accessRights.ForEach(delegate(recAccessRights.AccessRights access)
            {
                switch (access)
                {

                    case (recAccessRights.AccessRights.Add):
                        ClientScript.RegisterStartupScript(typeof(Page), "add", "$('#btnSave').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Edit):
                        ClientScript.RegisterStartupScript(typeof(Page), "edit", "$('#btnSave').show();", true);
                        break;
                }
            });
        }
    }
}
